package com.wink.charity;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.gson.Gson;
import com.wink.common.Identity;
import com.wink.service.CommunityServicesImpl;

@XmlRootElement(name = "charity")
@XmlAccessorType(XmlAccessType.FIELD)
public class Charity {	

	@XmlElement(name = "name")
	private String name;	
	
	@XmlElement(name = "description")
	private String description;
	
	@XmlElement(name = "charityCommunityID")
	private String charityCommunityID;	

	@XmlElement(name = "identity")
	private Identity identity;
	
	@XmlElement(name = "amount")
	private String amount;		

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getCharityCommunityID() {
		return charityCommunityID;
	}

	public void setCharityCommunityID(String charityCommunityID) {
		this.charityCommunityID = charityCommunityID;
	}

	public Identity getIdentity() {
		return identity;
	}

	public void setIdentity(Identity identity) {
		this.identity = identity;
	}
	
	public String getAmount() {
		return amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}
	
	public String toString() {
		StringBuffer sf = new StringBuffer();
		
		sf.append("<name> " + name);
		sf.append("<description> " + description);
		sf.append("<identity> " + identity.toString());
		sf.append("<charityCommunityID> " + charityCommunityID);
		sf.append("<amount> " + amount);
				
		return sf.toString();
	}
	
	public static String toJson(Charity charity) {
		Gson gson = new Gson();
		String json = gson.toJson(charity, Charity.class);
		System.out.println("---> Chairty: tojson  " + json);
		
		Charity retCh = gson.fromJson(json, Charity.class);
		return json;
	}
	
	public static Charity fromJson(String json) {
		Gson gson = new Gson();
		Charity retCh = gson.fromJson(json, Charity.class);
		System.out.println("---> Chairty: fromJson  " + retCh.toString());
		return retCh;
	}
	
	public static void main(String[] args) {
		// to String
		Charity c = new Charity();
		c.setName(" Charity from Client 11");
		c.setDescription("Test creating a Charity, Charity 11 from a client");
			Identity identity = new Identity();
			identity.setFromCommunity("ABPMClient");
			identity.setFromUser("PKRClient");
			identity.setDate(new Date());	
		c.setIdentity(identity);
		String json = new Charity().toJson(c);
		
		//to Charity
		Charity ch = new Charity();
		ch.fromJson(json); 
		
	}
	
}


